const moment = require('moment')
function getDate (someDate, n) {
  var datt = someDate.split('-')
  var newDate = new Date(datt[0], datt[1] - 1, datt[2])
  var befminuts = newDate.getTime() - 1000 * 60 * 60 * 24 * parseInt(n)
  var beforeDat = new Date()
  beforeDat.setTime(befminuts)
  var befMonth = beforeDat.getMonth() + 1
  var mon = befMonth >= 10 ? befMonth : '0' + befMonth
  var befDate = beforeDat.getDate()
  var da = befDate >= 10 ? befDate : '0' + befDate
  var newDate1 = beforeDat.getFullYear() + '-' + mon + '-' + da
  return newDate1
}

export function getDistantDay (res) {
  let index = 0
  const result = []
  for (let j = 0; j < res.length; j++) {
    result.push(res[j].loginDay)
  }
  for (let i = 0; i < res.length; i++) {
    const newDate = getDate(moment(Date.now()).format('YYYY-MM-DD'), i)
    if (result.indexOf(newDate) !== -1) {
      index++
    } else {
      break
    }
  }
  return index
}
export default function (res) {
  console.log(res, '传入的数据')
  let arr = []
  let result = []
  for (let j = 0; j < res.length; j++) {
    result.push(res[j].loginDay)
  }
  for (let i = 79; i >= 0; i--) {
    const newDate = getDate(moment(Date.now()).format('YYYY-MM-DD'), i)
    if (result.indexOf(newDate) !== -1) {
      arr.push({day: newDate, login: true})
    } else {
      arr.push({day: newDate, login: false})
    }
  }
  return arr
}
